package com.CNMedical.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.CNMedical.common.annotation.Log;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.AjaxResult;
import com.CNMedical.common.enums.BusinessType;
import com.CNMedical.system.domain.entity.AppletQuestionAnswer;
import com.CNMedical.system.service.IAppletQuestionAnswerService;
import com.CNMedical.common.utils.poi.ExcelUtil;
import com.CNMedical.common.core.page.TableDataInfo;

/**
 * 试题-答案关联Controller
 * 
 * @author tang
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/system/question-answer")
public class AppletQuestionAnswerController extends BaseController
{
    @Autowired
    private IAppletQuestionAnswerService appletQuestionAnswerService;

    /**
     * 查询试题-答案关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:answer:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletQuestionAnswer appletQuestionAnswer)
    {
        startPage();
        List<AppletQuestionAnswer> list = appletQuestionAnswerService.selectAppletQuestionAnswerList(appletQuestionAnswer);
        return getDataTable(list);
    }

    /**
     * 导出试题-答案关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:answer:export')")
    @Log(title = "试题-答案关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletQuestionAnswer appletQuestionAnswer)
    {
        List<AppletQuestionAnswer> list = appletQuestionAnswerService.selectAppletQuestionAnswerList(appletQuestionAnswer);
        ExcelUtil<AppletQuestionAnswer> util = new ExcelUtil<AppletQuestionAnswer>(AppletQuestionAnswer.class);
        util.exportExcel(response, list, "试题-答案关联数据");
    }

    /**
     * 获取试题-答案关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:answer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appletQuestionAnswerService.selectAppletQuestionAnswerById(id));
    }

    /**
     * 新增试题-答案关联
     */
    @PreAuthorize("@ss.hasPermi('system:answer:add')")
    @Log(title = "试题-答案关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletQuestionAnswer appletQuestionAnswer)
    {
        return toAjax(appletQuestionAnswerService.insertAppletQuestionAnswer(appletQuestionAnswer));
    }

    /**
     * 修改试题-答案关联
     */
    @PreAuthorize("@ss.hasPermi('system:answer:edit')")
    @Log(title = "试题-答案关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletQuestionAnswer appletQuestionAnswer)
    {
        return toAjax(appletQuestionAnswerService.updateAppletQuestionAnswer(appletQuestionAnswer));
    }

    /**
     * 删除试题-答案关联
     */
    @PreAuthorize("@ss.hasPermi('system:answer:remove')")
    @Log(title = "试题-答案关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletQuestionAnswerService.deleteAppletQuestionAnswerByIds(ids));
    }
}
